#INCLUDE "PROTHEUS.CH"
#INCLUDE "APWEBEX.CH"

User Function fswpva02()
local cHtml:= ""
Private oObj := Nil

WEB EXTENDED INIT cHtml

If !Empty(HttpSession->aUser) .and. !Empty(HttpSession->aComan)
	Return cHtml := RedirPage(" u_fswpva03.apw ")
ElseIf Empty(HttpSession->aUser) .and. Empty(HttpSession->aComan)

	If Empty(HTTPPOST->CUSER) .And. Empty(HTTPPOST->CSENHA)
		Return cHtml := RedirPage("u_fswpva01.apw")
	Else
		oObj := WSUSERPORTAL():New()
		oObj:CUSERLOGIN := HTTPPOST->CUSER
		oObj:CUSERPASSWORD := HTTPPOST->CSENHA
		If oObj:PRTLOGIN()
			conout("Usuario logado: "+oObj:OWSPRTLOGINRESULT:CUSERNAME)
			HttpSession->aUser := {oObj:OWSPRTLOGINRESULT:CUSERCODE,HTTPPOST->CUSER,oObj:OWSPRTLOGINRESULT:CUSERNAME,oObj:OWSPRTLOGINRESULT:CUSEREMAIL}
			cHtml := "OK"
		Else
			cHtml := GetWSCerror(3)
		EndIf
	EndIf
ElseIf Empty(HttpSession->aUser) .and. !Empty(HttpSession->aComan)
	HttpSession->aComan := {}
	Return cHtml := RedirPage("u_fswpva01.apw")
Else
	Return cHtml := ExecInPage("fswpvh02")
EndIf

WEB EXTENDED END
Return cHtml